using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;

namespace InvestmentIntelligence.DbModel.Models
{
    public class OriginalPosition
    {
        private sealed class FundBookEntityIdSecurityIdDateEqualityComparer : IEqualityComparer<OriginalPosition>
        {
            public bool Equals(OriginalPosition x, OriginalPosition y)
            {
                if (ReferenceEquals(x, y)) return true;
                if (ReferenceEquals(x, null)) return false;
                if (ReferenceEquals(y, null)) return false;
                return x.FundBookEntityId == y.FundBookEntityId && x.SecurityId == y.SecurityId && x.Date.Equals(y.Date);
            }

            public int GetHashCode(OriginalPosition obj)
            {
                unchecked
                {
                    var hashCode = obj.FundBookEntityId;
                    hashCode = (hashCode*397) ^ obj.SecurityId;
                    hashCode = (hashCode*397) ^ obj.Date.GetHashCode();
                    return hashCode;
                }
            }
        }

        private static readonly IEqualityComparer<OriginalPosition> OriginalPositionIndexEqualityComparerInstance = new FundBookEntityIdSecurityIdDateEqualityComparer();

        public static IEqualityComparer<OriginalPosition> OriginalPositionIndexEqualityComparer
        {
            get { return OriginalPositionIndexEqualityComparerInstance; }
        }

        [Key, Column(Order = 0)]
        public int FundBookEntityId { get; set; }

        [Key, Column(Order=1)]
        public int SecurityId { get; set; }
      
        [Key, Column(Order = 2)]
        public DateTime Date { get; set; }

        public Nullable<decimal> CloseQuantity { get; set; }
        public Nullable<decimal> PositionPL { get; set; }
        public Nullable<decimal> TradePL { get; set; }
        public Nullable<decimal> CloseExposure { get; set; }
        public virtual FundBookEntity FundBookEntity { get; set; }
        public virtual Security Security { get; set; }
        public virtual OriginalPositionValidationData OriginalPositionValidationData { get; set; }


        public override string ToString()
        {
            return string.Format("SecurityId: {0}, FundBookEntityId: {1}, Date: {2}, CloseQuantity:{3}", SecurityId, FundBookEntityId, Date, CloseQuantity);
        }
    }
}
